package com.mouse.hxsj.util;

import com.mouse.damo.micro.Com;
import com.mouse.damo.micro.FindStr;
import com.mouse.damo.micro.Window;
import com.mouse.damo.util.StringUtil;
import com.mouse.hxsj.entity.common.GameMap;
import com.mouse.hxsj.entity.common.Point;

import java.util.List;

public class CommonUtil {
    public static GameMap getMap(Com com) {
        com.setDict(0, "坐标.txt");
        FindStr findStr = new FindStr(com);
        Window window = new Window(com);
        boolean windowState = window.windowState(com.getHwnd(), 3);
        if(windowState)return new GameMap();
        int[] size = window.getClientSize(com.getHwnd());
        int y1 = 2, y2 = 22;
//        int x1=876,x2=992;
        int x1=size[1]-(1024-876),x2=size[1]-(1024-992);
        String str = findStr.readStr(x1, y1, x2, y2, "3db2ff-000000", "", 0.9, 0);
        str = StringUtil.isNotBlank(str) ? str : findStr.readStr(x1, y1, x2, y2, "ffffff-000000", "", 0.9, 0);
        str = StringUtil.isNotBlank(str) ? str : findStr.readStr(x1, y1, x2, y2, "71d117-000000", "", 0.9, 0);
        System.out.print(" "+str);
        if (StringUtil.isBlank(str)) return new GameMap("");
        String map = str.replaceAll("[0-9,]", "");
        String point = str.replaceAll("[^0-9,]", "");
        List<Point> list = DamoUtil.picsToPoint(point);
        GameMap gameMap = new GameMap();
        if(list.size()==0)return gameMap;
        Point point1 = list.get(0);
        gameMap.setMap(map);
        gameMap.setX(point1.getX());
        gameMap.setY(point1.getY());
        return gameMap;
    }
    public static void main(String[] args) {
        Com com = new Com();
        com.setResourcePath("D:\\damo");
        com.setDict(0, "坐标.txt");
        int hwnd=132844;
        boolean bind = com.bind(hwnd);
        Window window = new Window(com);
        int[] windowRect = window.getClientSize(hwnd);
        System.out.println(JsonUtil.toJson(windowRect));


        GameMap gameMap = getMap(com);
        System.out.println(JsonUtil.toJson(gameMap));
    }
}
